<html>
  <head>
    <title>MySQL Tabellen Inzien</title>
    <link rel="stylesheet" href="http://frankkie.nl/frankkie.css" type="text/css" />
  </head><body>
    <h2>Database Inzien</h2>

    <h3>Tabel inzien</h3>
    <h4><a href="index.php">index</a></h4>
    <a href="inzien.php">Andere tabel/db</a><br />

    <%
   //if (!$_GET[welkedb]){
   if (request.getParameter("welkedb") == null) {
    %>
    <form>
      <input type="submit" value="Klik" />
      <select name="welkedb">
        <option value="school">School Database (mysql.cmi-hro.nl)</option>
      </select>
    </form>
    <%   }

   //String maken.
   String dbhost, dbpass, dbname, dbselect;

   //if ($_GET[welkedb])
   if (request.getParameter("welkedb") != null) {
     //if ($_GET[welkedb] == "school"){
     if (request.getParameter("welkedb").equals("school")) {
       dbhost = "mysql.cmi-hro.nl";
       dbname = "cmi0806683";
       dbpass = "onthouden";
       dbselect = dbname;
     }


     //if (!$_GET[tabel]){
     if (request.getParameter("tabel") == null) {
       //$db=mysql_connect($dbhost,$dbname,$dbpass)
       eskuel.CMI_SQL sql = new eskuel.CMI_SQL(pin.Database.dbhost, pin.Database.dbname, pin.Database.dbpass);
       //or die("Kan niet verbinden met MySQL.<br />".mysql_error());
       //mysql_select_db($dbselect);
       //array met de tabellen
       java.sql.ResultSet resultaat = sql.selectieQuery("SHOW TABLES");
       String dinges = "";
       try {
        while (resultaat.next()) {
          dinges += resultaat.getString(0);
          System.out.println(resultaat.getString(0));
        }
        System.out.println("Dinges: " + dinges);
      } catch (Exception e) {
        System.out.println("Fout bij DB.");
      }
       /*
       if (mysql_num_rows($tabellenResultaat) > 0) {
         while ($rij = mysql_fetch_array($tabellenResultaat)) {
           $tabellen[]
           = $rij[0];
         }
       } else {
         echo

       "Geen Tabellen Gevonden";
       }*/
      ///
       echo

          "<form><select name=\"tabel\">\n";
       foreach ($tabellen as $key = > $value

         ){
        echo

       "<option value=\"$value\">$value</option>";
       }
       echo





         "</select><input type=\"hidden\" name=\"welkedb\" value=\"$_GET[welkedb]\" /><input type=\"submit\" value=\"Ok\" /></form>";
     } else {
    ///////////////////////////

     //deze pagina laat de inhoud van 1 tabel zien.

      $db=mysql_connect($dbhost,$dbname,$dbpass)
      or die("Kan niet verbinden met MySQL.<br />".mysql_error());
      mysql_select_db($dbselect);

     $sql="SELECT * FROM `".$_GET[tabel].




          "`";
     echo $sql."<br />";
     $resultaat=mysql_query($sql);
     $num_rows=mysql_num_rows($resultaat);
     echo $num_rows."<br />";

      if ($num_rows > 0) {
         echo
           "<table border=\"1\"><tr>\n";

     $i = 0;
         while ($i < mysql_num_fields($resultaat)) {
           $meta = mysql_fetch_field($resultaat, $i);
           if ($meta) {
             echo
                "<th>";
       if ($meta- > primary_key > 0) {
               echo


             "<u>";
       }
       echo $meta->name;
             if ($meta ->  primary_key > 0) {
               echo

             "</u>";
       }
       echo

           "</th>\n";
         }
         $i++;
     }
     echo

           "</tr>\n\n";

       while ($rij = mysql_fetch_array($resultaat,MYSQL_ASSOC))
        {
        echo



             "<tr>";
        foreach ($rij as $value)
        {
         echo

           "<td>$value";
        }
        echo





 "</tr>\n";
        }
      }
     mysql_close($db);
     ////////////////////////////////////
     }
    }
%></body></html>